package com.ctgu.蓝桥杯真题.B组2018;

import java.io.*;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;

/**
 * @author: Backdiy
 * @data: 2021/4/13 12:41
 * @desc:
 */
/*
7
.......
.##....
.##....
....##.
..####.
...###.
.......
 */
public class I全球变暖 {
    static int n;
    static int ans = 0;
    static int[][] dir = new int[][]{{-1, 0}, {1, 0}, {0, -1}, {0, 1}};
    static int[][] vis;
    static String[] map;

    public static void main(String[] args) throws IOException {
        Scanner scanner = new Scanner(System.in);
        n = scanner.nextInt();
        map = new String[n + 10];
        vis = new int[n + 10][n + 10];
        for (int i = 1; i <= n; i++) {
            String s = scanner.next();
            map[i] = " " + s + " ";
        }
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= n; j++) {
                //搜索每一个小岛
                if (map[i].charAt(j) == '#' && vis[i][j] == 0) {
                    bfs(i, j);
                }
            }
        }
        System.out.println(ans);
    }

    static void bfs(int a, int b) {
        int cnt = 0, res = 0;
        vis[a][b] = 1;
        Queue<P> q = new LinkedList<>();
        P p0 = new P(a, b);
        q.add(p0);
        while (!q.isEmpty()) {
            cnt++;
            P p = q.poll();
            int xx = p.x;
            int yy = p.y;
            if (check(xx, yy)) {
                res++;
            }
            for (int i = 0; i < 4; i++) {
                int x = dir[i][0] + xx;
                int y = dir[i][1] + yy;
                if (x >= 1 && y >= 1 && x <= n && y <= n)
                    if (map[x].charAt(y) == '#' && vis[x][y] == 0) {
                        q.add(new P(x, y));
                        vis[x][y] = 1;
                    }
            }
        }
        //判断在这个小岛种接近海面的陆地面积是否等于小岛的面积
        if (res == cnt) {
            ans++;
        }
    }

    static boolean check(int a, int b) {
        for (int i = 0; i < 4; i++) {
            int x = a + dir[i][0];
            int y = b + dir[i][1];
            if (x > 0)
                if (map[x].charAt(y) == '.') return true;
        }
        return false;
    }

    static class P {
        int x, y;

        public P(int x, int y) {
            this.x = x;
            this.y = y;
        }
    }
}
